﻿using Magicodes.ExporterAndImporter.Excel.AspNetCore;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using System.Net.Http.Headers;
using WhutDoomCheck.Server.Configs;
using WhutDoomCheck.Server.Services;

namespace WhutDoomCheck.Server.Controllers
{
    [Route("api/[controller]")]
    [ApiController]
    [Authorize(IdentityPolicyNames.School)]
    public class SchoolController : ControllerBase
    {
        public SchoolController(ExportService exportService)
        {
            this.exportService = exportService;
        }

        private readonly ExportService exportService;

        [HttpGet("[Action]")]
        public async Task<IActionResult> ExportAllStudents()
        {
            return new XlsxFileResult(await exportService.ExportAllStudents());
        }

        [HttpGet("[Action]")]
        public async Task<IActionResult> ExportAllStudentsDivideBySchool()
        {
            return new FileStreamResult(new MemoryStream(await exportService.ExportAllStudentsDividedBySchoolZipped()), "application/x-zip-compressed");
        }

        [HttpGet("[Action]")]
        public async Task<IActionResult> ExportSchoolStatus()
        {
            return new XlsxFileResult(await exportService.ExportSchoolStatus());
        }

        [HttpGet("[Action]")]
        public async Task<IActionResult> ExportUnfinishedStudents()
        {
            return new XlsxFileResult(await exportService.ExportAllUnfinished());
        }

        [HttpGet("[Action]")]
        public async Task<IActionResult> ExportEmptyBeds()
        {
            return new XlsxFileResult(await exportService.ExportEmptyBeds());
        }
    }
}
